<?php
/**
 * Created by PhpStorm.
 * User: user1
 * Date: 2018/9/3
 * Time: 11:04
 */

namespace app\admin\controller;


use app\common\service\UploadService;
use think\Controller;
use think\facade\Request;
use app\common\model\Region as RegionModel;

class Base extends Controller
{
    // 错误页面
    public function error_page() {
        $this->assign('error_msg', input('param.msg'));
        return view();
    }

    /**
     * 上传图片
     */
    public function upload_image() {
        $data = UploadService::upload_image();
        return json([
            'code' => 0,
            'msg' => $data['msg'],
            'data' => [
                'src' => $data['path']
            ]
        ]);
    }

//    public function save_add() {
//        if (Request::isAjax()) {
//            $add = input('param.add');
//
////            foreach($add as $v) {
//                $rm = RegionModel::create([
//                    'name' => $add['name']
//                ]);
//
//                if (isset($add['sub']) && $one_sub = $add['sub']) {
//                    foreach ($one_sub as $ov) {
//                        $o_rm = RegionModel::create([
//                            'pid' => $rm->id,
//                            'name' => $ov['name']
//                        ]);
//
//                        if (isset($ov['sub']) && $two_sub = $ov['sub']) {
//                            foreach ($two_sub as $tv) {
//                                RegionModel::create([
//                                    'pid' => $o_rm->id,
//                                    'name' => $tv['name']
//                                ]);
//                            }
//                        }
//                    }
//                }
////            }
//
//            return [];
//        }
//        return view();
//    }
}